package com.ruoyi.web.controller.system;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.SparePartsInventory;
import com.ruoyi.system.service.ISparePartsInventoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 备件库存管理Controller
 *
 * @author ruoyi
 * @date 2025-03-19
 */
@RestController
@RequestMapping("/system/inventory")
public class SparePartsInventoryController extends BaseController {
    @Autowired
    private ISparePartsInventoryService sparePartsInventoryService;

    /**
     * 查询备件库存管理列表
     */
    //@PreAuthorize("@ss.hasPermi('system:inventory:list')")
    @GetMapping("/list")
    public TableDataInfo list(SparePartsInventory sparePartsInventory) {
        startPage();
        List<SparePartsInventory> list = sparePartsInventoryService.selectSparePartsInventoryList(sparePartsInventory);
        return getDataTable(list);
    }

    /**
     * 查询备件库存管理列表
     */
    //@PreAuthorize("@ss.hasPermi('system:inventory:list')")
    @GetMapping("/xialaxuan")
    public AjaxResult xialaxuan(SparePartsInventory sparePartsInventory) {
        List<SparePartsInventory> list = sparePartsInventoryService.selectSparePartsInventoryList(sparePartsInventory);
        return AjaxResult.success(list);
    }

    /**
     * 导出备件库存管理列表
     */
    //@PreAuthorize("@ss.hasPermi('system:inventory:export')")
    //@Log(title= "备件库存管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SparePartsInventory sparePartsInventory) {
        List<SparePartsInventory> list = sparePartsInventoryService.selectSparePartsInventoryList(sparePartsInventory);
        ExcelUtil<SparePartsInventory> util = new ExcelUtil<SparePartsInventory>(SparePartsInventory.class);
        util.exportExcel(response, list, "备件库存管理数据");
    }

    /**
     * 获取备件库存管理详细信息
     */
    //@PreAuthorize("@ss.hasPermi('system:inventory:query')")
    @GetMapping(value = "/{partNo}")
    public AjaxResult getInfo(@PathVariable("partNo") String partNo) {
        return success(sparePartsInventoryService.selectSparePartsInventoryByPartNo(partNo));
    }

    /**
     * 新增备件库存管理
     */
    //@PreAuthorize("@ss.hasPermi('system:inventory:add')")
    //@Log(title= "备件库存管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SparePartsInventory sparePartsInventory) {
        return toAjax(sparePartsInventoryService.insertSparePartsInventory(sparePartsInventory));
    }

    /**
     * 修改备件库存管理
     */
    //@PreAuthorize("@ss.hasPermi('system:inventory:edit')")
    //@Log(title= "备件库存管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SparePartsInventory sparePartsInventory) {
        return toAjax(sparePartsInventoryService.updateSparePartsInventory(sparePartsInventory));
    }

    /**
     * 删除备件库存管理
     */
    //@PreAuthorize("@ss.hasPermi('system:inventory:remove')")
    //@Log(title= "备件库存管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{partNos}")
    public AjaxResult remove(@PathVariable String[] partNos) {
        return toAjax(sparePartsInventoryService.deleteSparePartsInventoryByPartNos(partNos));
    }
}
